package com.wss.juc;

import java.util.concurrent.CountDownLatch;

public class ThreadSyncExample {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);

        Thread thread1 = new Thread(() -> {
            System.out.println("A");
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            System.out.println("C");
        });

        Thread thread2 = new Thread(() -> {
            try {

                Thread.sleep(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            System.out.println("B");
            latch.countDown();
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();
    }
}